/*-------------------------------------------
UART串口通信
add by mtd at 20240521
----------------------------------------------*/
#include "../../include/taiic_uart/taiic_uart_sum.h"
#include <fstream>
#include "rk_debug.h"
#include <stdio.h>
#include <unistd.h> // Unix 标准函数定义
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <fcntl.h> // 文件控制定义
#include <iostream>
#include <termios.h> // PPSIX 终端控制定义
#include <cstring>   // 字符串功能
#include <errno.h>   // 错误号定义
#include <thread>
#include <chrono>

using namespace std;

int pam1 = 0;
int pam2 = 0;
int pam3 = 0;
int pam4 = 0;
/*-------------------------main-------------------------*/
int main(int argc, char *argv[])
{
    int rst = 0;
    // 传参
    if (argc < 2)
    {
        printf("No rgument provided.\n");
    }
    else if(argc == 2)
    {
        pam1 = atoi(argv[1]);
    }
    else if (argc == 3)
    {
        pam1 = atoi(argv[1]);
        pam2 = atoi(argv[2]);
    }
    else if (argc == 5)
    {
        pam1 = atoi(argv[1]);
        pam2 = atoi(argv[2]);
        pam3 = atoi(argv[3]);
        pam4 = atoi(argv[4]);
        printf("param3-4:%d,%d\n", pam3, pam4);
    }
    printf("param:%d,%d\n", pam1, pam2);

    // 串口初始化
    serial_init();

    if (pam1 == 6)
    {
        rst = battery_status_notify_cmd_function(pam2, pam3, pam4); // 电池电量的UART传输
    }
    else
    {
        rst = command_uart_transform(pam1, pam2);
    }
    std::this_thread::sleep_for(std::chrono::milliseconds(100));//每个指令间隔100ms
    
    // 释放循环缓冲区
    serialData.releaseRingbuffer();
    return 0;
}
